/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "AssetsAnalyzeDialog.h"
#include "DepositManager.h"

namespace QSThink
{
	AssetsAnalyzeDialog::AssetsAnalyzeDialog(QWidget *parent)
		: QDialog(parent),_ui(new Ui::AssetsAnalyzeWidget)
	{
		_ui->setupUi(this);

		connect(_ui->buttonOK,SIGNAL(clicked(bool)),this,SLOT(OnOKClicked(bool)));

		loadAssetsInfo();
	}

	AssetsAnalyzeDialog::~AssetsAnalyzeDialog()
	{
		delete _ui;
	}

	void AssetsAnalyzeDialog::OnOKClicked( bool checked )
	{
		this->hide();

	}

	void AssetsAnalyzeDialog::loadAssetsInfo()
	{
		//int portCap=PortfolioManager::getSingleton().getCapital();
		float exchange=PortfolioManager::getSingleton().getCapital();
		float currency=DepositManager::getSingleton().getCapital();
		float total=exchange+currency;

		_ui->labelExchange->setText(QString::number(exchange));
		_ui->labelCurrency->setText(QString::number(currency));
		_ui->labelTotal->setText(QString::number(total,'g', 12));

	}

	void AssetsAnalyzeDialog::OnPortfolioAdded( QString symbol )
	{
		//int portCap=PortfolioManager::getSingleton().getCapital();
		float exchange=PortfolioManager::getSingleton().getCapital();
		float currency=DepositManager::getSingleton().getCapital();
		float total=exchange+currency;

		_ui->labelExchange->setText(QString::number(exchange));
		_ui->labelCurrency->setText(QString::number(currency));
		_ui->labelTotal->setText(QString::number(total,'g', 12));

	}

	void AssetsAnalyzeDialog::OnPortfolioRemoved( QString symbol )
	{

		//int portCap=PortfolioManager::getSingleton().getCapital();
		float exchange=PortfolioManager::getSingleton().getCapital();
		float currency=DepositManager::getSingleton().getCapital();
		float total=exchange+currency;

		_ui->labelExchange->setText(QString::number(exchange));
		_ui->labelCurrency->setText(QString::number(currency));
		_ui->labelTotal->setText(QString::number(total,'g', 12));
	}

	void AssetsAnalyzeDialog::OnPortfolioUpdated( PortfolioItem* item )
	{
		//int portCap=PortfolioManager::getSingleton().getCapital();
		float exchange=PortfolioManager::getSingleton().getCapital();
		float currency=DepositManager::getSingleton().getCapital();
		float total=exchange+currency;

		_ui->labelExchange->setText(QString::number(exchange));
		_ui->labelCurrency->setText(QString::number(currency));
		_ui->labelTotal->setText(QString::number(total,'g', 12));

	}


}
